import * as changeCase from 'change-case';
import React from 'react';

const factroy = require.context('@ant-design/icons', false, /.*Outlined\.js$/);

const iconsMap = factroy.keys().reduce((acc, key) => {
  const name = key.replace('./', '').replace('.js', '');
  return {
    ...acc,
    [changeCase.paramCase(name)]: factroy(key).default,
  };
}, {});

const Icon = ({ type, ...props }) => {
  const Component = iconsMap[type] ? iconsMap[type] : () => <></>;
  return <Component {...props} />;
};

Icon.iconNames = Object.keys(iconsMap);

export default Icon;
